#include<stdio.h>

#define MAXLINE 100
#define YES 1
#define NO 0

int htoi(char s[]);

int main(void)
{
    int value;
    value = htoi("0xff");
    printf("The value is %d\n", value);
    return 0;
}

int htoi(char s[])
{
    int hexdigit,i,inhex,n;
    i = 2;
    n = 0;
    inhex = YES;

    for(;inhex==YES;++i)
    {
        if(s[i] >='0' && s[i] <='9')
            hexdigit= s[i] - '0';
        else if(s[i] >='a' && s[i] <='f')
            hexdigit= s[i] -'a' + 10;
        else if(s[i] >='A' && s[i] <='F')
            hexdigit= s[i] -'A' + 10;
        else
            inhex = NO;

        if(inhex == YES)
            n = 16 * n + hexdigit;
    }
    return n;
}